#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <sstream>

using namespace std;


void function();
void writeUser(string ID, string name, string pwd);
void writeGood(string ID, string name, string type, int originalNum, int outNum, int inNum, int finalNum);
void query();
void suppliermanagement();
void customermanagement();

//登录后的菜单
void menuLogin() {
	cout << " ---------------------------欢迎使用仓库管理系统-------------------------" << endl;
	cout << " |                         1、查询功能                                  |" << endl;
	cout << " |                         2、仓库管理                                  |" << endl;
	cout << " |                         3、供应商管理                                |" << endl;
	cout << " |                         4、客户管理                                  |" << endl;
	cout << " |                         5、返回                                      |" << endl;
	cout << " ------------------------------------------------------------------------" << endl;
	cout << "请输入你的选择:";
}
// 仓库管理的菜单
void menuWarehouseManagement() {
	cout << " ---------------------------仓库管理---------------------------" << endl;
	cout << " |                         1、入库功能                        |" << endl;
	cout << " |                         2、出库功能                        |" << endl;
	cout << " |                         3、添加商品功能                    |" << endl;
	cout << " |                         4、删除商品功能                    |" << endl;
	cout << " |                         5、返回                            |" << endl;
	cout << " --------------------------------------------------------------" << endl;
	cout << "请输入你的选择:";
}
// 供应商管理的菜单
void menuSupplierManagement() {
	cout << " ---------------------------供应商管理---------------------------" << endl;
	cout << " |                         1、添加供应商                        |" << endl;
	cout << " |                         2、删除供应商                        |" << endl;
	cout << " |                         3、修改供应商信息                    |" << endl;
	cout << " |                         4、查询供应商信息                    |" << endl;
	cout << " |                         5、返回                              |" << endl;
	cout << " ----------------------------------------------------------------" << endl;
	cout << "请输入你的选择:";
}
// 客户管理的菜单
void menuCustomerManagement() {
	cout << " ---------------------------客户管理-----------------------------" << endl;
	cout << " |                         1、添加客户                          |" << endl;
	cout << " |                         2、删除客户                          |" << endl;
	cout << " |                         3、修改客户信息                      |" << endl;
	cout << " |                         4、查询客户信息                      |" << endl;
	cout << " |                         5、返回                              |" << endl;
	cout << " ---------------------------------------------------------------" << endl;
	cout << "请输入你的选择:";
}

//查询功能的菜单
void menuQuery() {
	cout << " ---------------------------欢迎使用仓库管理系统------------------------" << endl;
	cout << " |                         1、查询账号信息                              |" << endl;
	cout << " |                         2、查询库存信息                              |" << endl;
	cout << " |                         3、返回                                      |" << endl;
	cout << " -----------------------------------------------------------------------" << endl;
	cout << "请输入你的选择:";
}

//总菜单
void menuSub() {
	cout << " ---------------------------欢迎使用仓库管理系统------------------------" << endl;
	cout << " |                         1、注册账号                                 |" << endl;
	cout << " |                         2、登录系统                                 |" << endl;
	cout << " |                         3、退出系统                                 |" << endl;
	cout << " -----------------------------------------------------------------------" << endl;
	cout << "请输入你的选择:";
};

//user类
class user {
private:
	string ID;
	string Name;
	string Password;
public:
	user() {};
	void Register();
	void Enter();
	void queryUser();
	void readUser(string number);
};

//读取用户的信息
void user::readUser(string number) {
	string IDStr, nameStr, pwdStr;
	istringstream is(number);
	is >> IDStr >> nameStr >> pwdStr;
	this->ID = IDStr;
	this->Name = nameStr;
	this->Password = pwdStr;
}
//当前用户nowUser
user nowUser;

//注册功能
void user::Register()
{
	string pw1;
	string pw2;
	user person;
flag:
	cout << "请设置您的ID:";
	cin >> person.ID;
	ifstream rfile;
	rfile.open("user.csv", ios::in);
	string temp;
	user u;
	while (getline(rfile, temp)) {
		u.readUser(temp);
		if (u.ID == person.ID) {
			cout << "该ID已存在，请重新设置!" << endl;
			goto flag;
		}
	}
	cout << "请设置您的用户名:";
	cin >> person.Name;
	cout << "请设置您的密码:";
flag0:
	cin >> pw1;
	cout << "请再次确认您的密码:";
	cin >> pw2;
	if (pw1 != pw2)
	{
		cout << "前后两次输入密码不一致，请重新设置密码!" << endl;
		goto flag0;
	}
	person.Password = pw1;
	writeUser(person.ID, person.Name, person.Password);
	cout << "\n" << endl;
	cout << "用户[" << person.Name << "]注册成功!" << endl;
	system("pause");//保证命令窗口的打开

};

//登录功能
void user::Enter()
{
	char choice;
flag1:
	cout << "请输入你的ID:";
	string id;
	cin >> id;
	ifstream rfileId;
	rfileId.open("user.csv", ios::in);
	string tempId;
	user userId;
	while (getline(rfileId, tempId)) {
		userId.readUser(tempId);
		if (userId.ID == id) {
			goto flag2;
		}
	}
	rfileId.close();
	cout << "该ID不存在，请重新输入!(若还未注册，请输入0返回总菜单，输入1再次尝试ID)" << endl;
	cout << "0 or 1:";
	cin >> choice;
	if (choice == '0') {
		// 返回主菜单
		return;
	}
	else {
		goto flag1;
	}

flag2:
	cout << "请输入你的密码:";
	string pwd;
	cin >> pwd;
	ifstream rfilePwd;
	rfilePwd.open("user.csv", ios::in);
	string tempPwd;
	user userPwd;
	while (getline(rfilePwd, tempPwd)) {
		userPwd.readUser(tempPwd);
		if (userPwd.ID == id)
		{
			if (userPwd.Password == pwd)
			{
				break;
			}
			else
			{
				cout << "密码错误，请重新输入!" << endl;
				system("pause");
				goto flag2;
			}
		}
	}
	nowUser = userPwd;
	cout << "\n" << endl;
	cout << "用户[" << userPwd.Name << "]登录成功!" << endl;
	system("pause");
	function();
};

//显示当前用户的信息
void user::queryUser() {
	cout << "您的ID为:" << this->ID << endl;
	cout << "您的密码为:" << this->Password << endl;
	cout << "您的用户名为:" << this->Name << endl;
	system("pause");
}
//将注册的用户信息写入user.csv
void writeUser(string ID, string name, string pwd) {
	// 使用 stringstream 进行字符串拼接
	stringstream ss;
	ss << ID << ' ' << name << ' ' << pwd << '\n';
	string line = ss.str();

	// 使用 ofstream 打开文件，并使用 << 操作符写入数据
	ofstream wfile("user.csv", ios::out | ios::app);
	if (wfile.is_open()) {
		wfile << line;
		wfile.close();
	}
	else {
		cerr << "打开失败!" << endl;
	}
}


//good类
class good {
private:
	string ID;
	string Name;
	string type;
	int originalNum;
	int outNum;
	int inNum;
	int finalNum;
public:
	good() {};
	void queryGood();
	void library();
	void readGood(string number);
	void outbound();
	void deleteGood();
};

//vector是一个封装了动态大小数组的顺序容器,用于存放所有商品的信息
vector<good> goods;

void writeGood(string ID, string name, string type, int originalNum, int outNum, int inNum, int finalNum) {
	// 使用std::to_string来转换整数为字符串
	string originalNumStr = to_string(originalNum);
	string outNumStr = to_string(outNum);
	string inNumStr = to_string(inNum);
	string finalNumStr = to_string(finalNum);

	// 打开文件并写入数据
	ofstream wfile("good.csv", ios::out | ios::app);
	if (wfile.is_open()) {
		wfile << ID << " " << name << " " << type << " " << originalNumStr << " " << outNumStr << " " << inNumStr << " " << finalNumStr << "\n";
		wfile.close();
	}
	else {
		cerr << "打开失败！";
	}
}

//读取商品的信息
void good::readGood(string number) {
	string IDStr, nameStr, typeStr, originalNumStr, outNumStr, inNumStr, finalNumStr;
	istringstream is(number);
	is >> IDStr >> nameStr >> typeStr >> originalNumStr >> outNumStr >> inNumStr >> finalNumStr;
	stringstream ssOriginalNum;
	ssOriginalNum << originalNumStr;
	int originalNum;
	ssOriginalNum >> originalNum;
	stringstream ssOutNum;
	ssOutNum << outNumStr;
	int outNum;
	ssOutNum >> outNum;
	stringstream ssInNum;
	ssInNum << inNumStr;
	int inNum;
	ssInNum >> inNum;
	stringstream ssFinalNum;
	ssFinalNum << finalNumStr;
	int finalNum;
	ssFinalNum >> finalNum;
	this->ID = IDStr;
	this->Name = nameStr;
	this->type = typeStr;
	this->originalNum = originalNum;
	this->outNum = outNum;
	this->inNum = inNum;
	this->finalNum = finalNum;
}

//查询并显示对应商品的信息
void good::queryGood() {
	good findGood;
	string temp;
	string inNumber;
	ifstream rfile;
	rfile.open("good.csv", ios::in);
	int num = rfile.tellg();
	if (num == -1)
	{
		cout << "提示:找不到 good.csv 文件!" << endl;
		cout << "提示:请添加 good.csv 文件!" << endl;
		rfile.close();
	}
	else
	{
		rfile.close();
		while (1)
		{

			ifstream rfile;
			rfile.open("good.csv", ios::in);
			cout << "请输入查询商品的货品编号:";
			cin >> inNumber;
			while (getline(rfile, temp))
			{
				findGood.readGood(temp);
				if (findGood.ID == inNumber)
				{
					cout << "您的货品编号为:" << findGood.ID << endl;
					cout << "您的货品名称为:" << findGood.Name << endl;
					cout << "您的货品类型为:" << findGood.type << endl;
					cout << "您的原始库存为:" << findGood.originalNum << endl;
					cout << "您的进货数目为:" << findGood.inNum << endl;
					cout << "您的出货数目为:" << findGood.outNum << endl;
					cout << "您的最终库存为:" << findGood.finalNum << endl;
					rfile.close();
					goto flag3;
				}
			}
			cout << "输入有误，请重新输入!" << endl;
		}
	flag3:
		system("pause");
	}
}

//查询功能
void query()
{
	char choice;
	good queryGood;
	while (1)
	{
		system("cls");
		menuQuery();
		cin >> choice;
		switch (choice)
		{
		case '1':
			nowUser.queryUser();
			break;
		case '2':
			queryGood.queryGood();
			break;
		case '3':
			return;
			break;
		default:
			cout << "提示:请输入有误，重新输入!" << endl;
			system("pause");
		}
	}
}

//入库功能
void good::library() {
	ifstream rfile;
	good findGood;
	rfile.open("good.csv", ios::in);
	string temp;
	string inNumber;
	int num = rfile.tellg();
	if (num == -1)
	{
		//cout << "提示:找不到 good.csv 文件!" << endl;
		//cout << "提示:请添加 good.csv 文件!" << endl;
		cout << "提示:找不到 good.csv 文件!请选择添加商品功能以创建good.csv文件!" << endl;
		system("pause");
		return;
	}
	else
	{
		while (1)
		{
			cout << "请输入入库商品的货品编号:";
			cin >> inNumber;
			while (getline(rfile, temp))
			{
				findGood.readGood(temp);
				if (findGood.ID == inNumber)
				{
					goto flag4;
				}
			}
			cout << "商品不存在，返回!" << endl;
			system("pause");
			return;
		}
	flag4:
		cout << "请输入入库的数目:";
		int libraryNumber;
		cin >> libraryNumber;
		int inNumTemp = findGood.inNum;
		int finalNumTemp = findGood.finalNum;
		findGood.inNum += libraryNumber;
		findGood.finalNum += libraryNumber;

		if (findGood.inNum < 0 || findGood.finalNum < 0 || libraryNumber < 0) {
			cout << "输入的数目错误，请重新输入!" << endl;
			findGood.inNum = inNumTemp;
			findGood.finalNum = finalNumTemp;
			goto flag4;
		}

		//将文件的数据全部取出，修改对应的那行数据，再写入文件
		rfile.seekg(0);
		good tempGood;
		string tempStr;
		while (getline(rfile, tempStr))
		{
			tempGood.readGood(tempStr);
			if (tempGood.ID == inNumber)
			{
				goods.push_back(findGood);//向容器中添加新的元素
			}
			else
			{
				goods.push_back(tempGood);
			}
		}
		ofstream f("good.csv", ios::trunc);
		f.close();
		for (int i = 0; i < goods.size(); i++)
		{
			writeGood(goods.at(i).ID, goods.at(i).Name, goods.at(i).type, goods.at(i).originalNum, goods.at(i).outNum, goods.at(i).inNum, goods.at(i).finalNum);
		}
		goods.clear();
	}
	cout << "\n" << endl;
	cout << "入库成功!" << endl;
	cout << "提示:当前入库的数目为:" << findGood.inNum << "，当前库存的数目为:" << findGood.finalNum << endl;
	system("pause");
}

//出库功能
void good::outbound() {
	ifstream rfile;
	good findGood;
	rfile.open("good.csv", ios::in);
	string temp;
	string inNumber;
	int num = rfile.tellg();
	if (num == -1)
	{
		//cout << "提示:找不到 good.csv 文件!" << endl;
		//cout << "提示:请添加 good.csv 文件!" << endl;
		cout << "提示:找不到 good.csv 文件!请选择添加商品功能以创建good.csv文件!" << endl;
		system("pause");
		return;
	}
	else
	{
		while (1)
		{
			cout << "请输入出库商品的货品编号:";
			cin >> inNumber;
			while (getline(rfile, temp))
			{
				findGood.readGood(temp);
				if (findGood.ID == inNumber)
				{
					goto flag5;
				}
			}
			cout << "输入有误，返回!" << endl;
			system("pause");
			return;
		}
	flag5:
		cout << "请输入出库的数目:";
		int outboundNumber;
		cin >> outboundNumber;
		int outNumTemp = findGood.outNum;
		int finalNumTemp = findGood.finalNum;
		findGood.outNum += outboundNumber;
		findGood.finalNum -= outboundNumber;
		if (findGood.outNum < 0 || findGood.finalNum < 0 || outboundNumber < 0) {
			cout << "输入的数目错误，请重新输入!" << endl;
			findGood.outNum = outNumTemp;
			findGood.finalNum = finalNumTemp;
			goto flag5;
		}

		//将文件的数据全部取出，修改对应的那行数据，清空文件数据，再重新写入文件
		rfile.seekg(0);
		good tempGood;
		string tempStr;
		while (getline(rfile, tempStr))
		{
			tempGood.readGood(tempStr);
			if (tempGood.ID == inNumber)
			{
				goods.push_back(findGood);
			}
			else
			{
				goods.push_back(tempGood);
			}
		}
		ofstream f("good.csv", ios::trunc);
		f.close();
		for (int i = 0; i < goods.size(); i++)
		{
			writeGood(goods.at(i).ID, goods.at(i).Name, goods.at(i).type, goods.at(i).originalNum, goods.at(i).outNum, goods.at(i).inNum, goods.at(i).finalNum);
		}
		goods.clear();
	}
	cout << "\n" << endl;
	cout << "出库成功!" << endl;
	cout << "提示:当前出库的数目为:" << findGood.outNum << "，当前库存的数目为:" << findGood.finalNum << endl;
	system("pause");
}

//添加商品功能
void addGood() {
	string addID;
	string addName;
	string addtype;
	int addOriginalNum;
	int addOutNum;
	int addInNum;
	int addFinalNum;
	cout << "请输入商品ID:";
	cin >> addID;
	cout << "请输入商品名称:";
	cin >> addName;
	cout << "请输入商品类型:";
	cin >> addtype;
	cout << "请输入商品原始库存:";
	cin >> addOriginalNum;
	cout << "请输入商品出库数目:";
	cin >> addOutNum;
	cout << "请输入商品入库数目:";
	cin >> addInNum;
	cout << "请输入商品最终数目:";
	cin >> addFinalNum;
	writeGood(addID, addName, addtype, addOriginalNum, addOutNum, addInNum, addFinalNum);
	cout << "\n" << endl;
	cout << "商品[" << addName << "]添加成功!" << endl;
	system("pause");
}

//删除商品功能
void good::deleteGood() {
	ifstream rfile;
	good findGood;
	rfile.open("good.csv", ios::in);
	string temp;
	string inNumber;
	int num = rfile.tellg();
	if (num == -1)
	{
		cout << "提示:找不到 good.csv 文件!" << endl;
		cout << "提示:请添加 good.csv 文件!" << endl;
		system("pause");
		return;
	}
	else
	{
		while (1)
		{
			cout << "请输入查询商品的货品编号:";
			cin >> inNumber;
			while (getline(rfile, temp))
			{
				findGood.readGood(temp);
				if (findGood.ID == inNumber)
				{
					goto flag6;
				}
			}
			cout << "输入有误，请重新输入!" << endl;
		}
	flag6:
		//将文件的数据全部取出，删除对应的那行数据，清空文件数据，再重新写入文件
		rfile.seekg(0);
		good tempGood;
		string tempStr;
		while (getline(rfile, tempStr))
		{
			tempGood.readGood(tempStr);
			if (tempGood.ID != inNumber)
			{
				goods.push_back(tempGood);
			}
		}
		ofstream f("good.csv", ios::trunc);
		f.close();
		for (int i = 0; i < goods.size(); i++)
		{
			writeGood(goods.at(i).ID, goods.at(i).Name, goods.at(i).type, goods.at(i).originalNum, goods.at(i).outNum, goods.at(i).inNum, goods.at(i).finalNum);
		}
		goods.clear();
	}
	cout << "\n" << endl;
	cout << "商品删除成功!" << endl;
	system("pause");
}
// 供应商类
class supplier {
public:
	string ID;
	string Name;
	string Contact;
	string Address;
	void readSupplier(const string& number);
	void querySupplier();
	void addSupplier();
	void deleteSupplier();
	void modifySupplier();
};
// 供应商列表
vector<supplier> suppliers;

void writeSupplier(string ID, string name, string Contact, string Address) {
	// 打开文件并写入数据
	ofstream wfile("supplier.csv", ios::out | ios::app);
	if (wfile.is_open()) {
		wfile << ID << " " << name << " " << Contact << " " << Address << "\n";
		wfile.close();
	}
	else {
		cerr << "打开失败！";
	}
}

// 读取供应商信息
void supplier::readSupplier(const string& number) {
	istringstream is(number);
	is >> ID >> Name >> Contact >> Address;
}

// 显示供应商信息
void supplier::querySupplier() {
	supplier findSupplier;
	string temp;
	string inNumber;
	ifstream rfile;
	rfile.open("supplier.csv", ios::in);
	int num = rfile.tellg();
	if (num == -1)
	{
		cout << "提示:找不到 supplier.csv 文件!" << endl;
		cout << "提示:请添加 supplier.csv 文件!" << endl;
		rfile.close();
	}
	else
	{
		rfile.close();
		while (1)
		{

			ifstream rfile;
			rfile.open("supplier.csv", ios::in);
			cout << "请输入查询供应商的编号:";
			cin >> inNumber;
			while (getline(rfile, temp))
			{
				findSupplier.readSupplier(temp);
				if (findSupplier.ID == inNumber)
				{
					cout << "供应商编号为:" << findSupplier.ID << endl;
					cout << "供应商名称为:" << findSupplier.Name << endl;
					cout << "供应商的联系方式为:" << findSupplier.Contact << endl;
					cout << "供应商的地址为:" << findSupplier.Address << endl;
					rfile.close();
					goto flag3;
				}
			}
			cout << "输入有误，请重新输入!" << endl;
		}
	flag3:
		system("pause");
	}

}

// 添加供应商
void supplier::addSupplier() {
	supplier newSupplier;
	cout << "请输入供应商编号:";
	cin >> newSupplier.ID;
	cout << "请输入供应商名称:";
	cin >> newSupplier.Name;
	cout << "请输入联系方式:";
	cin >> newSupplier.Contact;
	cout << "请输入地址:";
	cin >> newSupplier.Address;
	suppliers.push_back(newSupplier);
	ofstream write;
	write.open("supplier.csv", ios::app);
	write << newSupplier.ID << " " << newSupplier.Name << " " << newSupplier.Contact << " " << newSupplier.Address << "\n";
	write.close();
	cout << "供应商添加成功!" << endl;
	system("pause");
}

// 删除供应商
void supplier::deleteSupplier() {
	ifstream rfile;
	supplier findSupplier;
	rfile.open("supplier.csv", ios::in);
	string temp;
	string inNumber;
	int num = rfile.tellg();
	if (num == -1)
	{
		cout << "提示:找不到 supplier.csv 文件!" << endl;
		cout << "提示:请添加 supplier.csv文件!" << endl;
		system("pause");
		return;
	}
	else
	{
		while (1)
		{
			cout << "请输入删除客户编号:";
			cin >> inNumber;
			while (getline(rfile, temp))
			{
				findSupplier.readSupplier(temp);
				if (findSupplier.ID == inNumber)
				{
					goto flag7;
				}
			}
			cout << "输入有误，请重新输入!" << endl;
		}
	flag7:
		//将文件的数据全部取出，删除对应的那行数据，清空文件数据，再重新写入文件
		rfile.seekg(0);
		supplier tempSupplier;
		string tempStr;
		while (getline(rfile, tempStr))
		{
			tempSupplier.readSupplier(tempStr);
			if (tempSupplier.ID != inNumber)
			{
				suppliers.push_back(tempSupplier);
			}
		}
		ofstream f("costomer.csv", ios::trunc);
		f.close();
		for (int i = 0; i < suppliers.size(); i++)
		{
			writeSupplier(suppliers.at(i).ID, suppliers.at(i).Name, suppliers.at(i).Contact, suppliers.at(i).Address);
		}
		suppliers.clear();
	}
	cout << "\n" << endl;
	cout << "客户删除成功!" << endl;
	system("pause");
}

// 修改供应商信息
void supplier::modifySupplier() {
	string supplierId;
	cout << "请输入要修改信息的供应商编号:";
	cin >> supplierId;
	for (auto& s : suppliers) {
		if (s.ID == supplierId) {
			cout << "请输入新的供应商名称:";
			cin >> s.Name;
			cout << "请输入新的联系方式:";
			cin >> s.Contact;
			cout << "请输入新的地址:";
			cin >> s.Address;
			ofstream write;
			write.open("supplier.csv", ios::out);
			for (const auto& sup : suppliers) {
				write << sup.ID << " " << sup.Name << " " << sup.Contact << " " << sup.Address << "\n";
			}
			write.close();
			cout << "供应商信息修改成功!" << endl;
			system("pause");
			return;
		}
	}
	cout << "未找到供应商，请检查供应商编号!" << endl;
}
// 客户类
class customer {
public:
	string ID;
	string Name;
	string Contact;
	string Address;
	void readCustomer(const string& number);
	void queryCustomer();
	void addCustomer();
	void deleteCustomer();
	void modifyCustomer();
};

// 客户列表
vector<customer> customers;

void writeCustomer(string ID, string name, string Contact, string Address) {
	// 打开文件并写入数据
	ofstream wfile("customer.csv", ios::out | ios::app);
	if (wfile.is_open()) {
		wfile << ID << " " << name << " " << Contact << " " << Address << "\n";
		wfile.close();
	}
	else {
		cerr << "打开失败！";
	}
}

// 读取客户信息
void customer::readCustomer(const string& number) {
	istringstream is(number);
	is >> ID >> Name >> Contact >> Address;
}

// 显示客户信息
void customer::queryCustomer() {
	customer findCustomer;
	string temp;
	string inNumber;
	ifstream rfile;
	rfile.open("customer.csv", ios::in);
	int num = rfile.tellg();
	if (num == -1)
	{
		cout << "提示:找不到 customer.csv 文件!" << endl;
		cout << "提示:请添加 customer.csv 文件!" << endl;
		rfile.close();
	}
	else
	{
		rfile.close();
		while (1)
		{

			ifstream rfile;
			rfile.open("customer.csv", ios::in);
			cout << "请输入查询客户的编号:";
			cin >> inNumber;
			while (getline(rfile, temp))
			{
				findCustomer.readCustomer(temp);
				if (findCustomer.ID == inNumber)
				{
					cout << "客户编号：" << findCustomer.ID << endl;
					cout << "客户名称：" << findCustomer.Name << endl;
					cout << "联系方式：" << findCustomer.Contact << endl;
					cout << "地址：" << findCustomer.Address << endl;
					cout << endl;
					rfile.close();
					goto flag3;
				}
			}
			cout << "输入有误，请重新输入!" << endl;




		}
	flag3:
		system("pause");

	}

}

// 添加客户
void customer::addCustomer() {
	customer newCustomer;
	cout << "请输入客户编号:";
	cin >> newCustomer.ID;
	cout << "请输入客户名称:";
	cin >> newCustomer.Name;
	cout << "请输入联系方式:";
	cin >> newCustomer.Contact;
	cout << "请输入地址:";
	cin >> newCustomer.Address;
	customers.push_back(newCustomer);
	ofstream write;
	write.open("customer.csv", ios::app);
	write << newCustomer.ID << " " << newCustomer.Name << " " << newCustomer.Contact << " " << newCustomer.Address << "\n";
	write.close();
	cout << "客户添加成功!" << endl;
	system("pause");
}

// 删除客户
void customer::deleteCustomer() {
	ifstream rfile;
	customer findCustomer;
	rfile.open("customer.csv", ios::in);
	string temp;
	string inNumber;
	int num = rfile.tellg();
	if (num == -1)
	{
		cout << "提示:找不到 customer.csv 文件!" << endl;
		cout << "提示:请添加 customer.csv 文件!" << endl;
		system("pause");
		return;
	}
	else
	{
		while (1)
		{
			cout << "请输入删除客户编号:";
			cin >> inNumber;
			while (getline(rfile, temp))
			{
				findCustomer.readCustomer(temp);
				if (findCustomer.ID == inNumber)
				{
					goto flag8;
				}
			}
			cout << "输入有误，请重新输入!" << endl;
		}
	flag8:
		//将文件的数据全部取出，删除对应的那行数据，清空文件数据，再重新写入文件
		rfile.seekg(0);
		customer tempCustomer;
		string tempStr;
		while (getline(rfile, tempStr))
		{
			tempCustomer.readCustomer(tempStr);
			if (tempCustomer.ID != inNumber)
			{
				customers.push_back(tempCustomer);
			}
		}
		ofstream f("customer.csv", ios::trunc);
		f.close();
		for (int i = 0; i < customers.size(); i++)
		{
			writeCustomer(customers.at(i).ID, customers.at(i).Name, customers.at(i).Contact, customers.at(i).Address);
		}
		customers.clear();
	}
	cout << "\n" << endl;
	cout << "客户删除成功!" << endl;
	system("pause");
}

// 修改客户信息
void customer::modifyCustomer() {
	string customerId;
	cout << "请输入要修改信息的客户编号:";
	cin >> customerId;
	for (auto& c : customers) {
		if (c.ID == customerId) {
			cout << "请输入新的客户名称:";
			cin >> c.Name;
			cout << "请输入新的联系方式:";
			cin >> c.Contact;
			cout << "请输入新的地址:";
			cin >> c.Address;
			ofstream write;
			write.open("customer.csv", ios::out);
			for (const auto& cus : customers) {
				write << cus.ID << " " << cus.Name << " " << cus.Contact << " " << cus.Address << "\n";
			}
			write.close();
			cout << "客户信息修改成功!" << endl;
			system("pause");
			return;
		}
	}
	cout << "未找到客户，请检查客户编号!" << endl;
}

//仓库管理
void warehousemanagement(){
	while(1){
		system("cls");
		good g;
		int num = 0;
		menuWarehouseManagement();
		cin >> num;
		switch (num) {
		case 1:
			//入库
			g.library();
			break;
		case 2:
			//出库
			g.outbound();
			break;
		case 3:
			//删除商品
			addGood();
			break;
		case 4:
			//添加商品
			g.deleteGood();
			break;
		case 5:
			return;
			break;
		}
	}
}

//供应商管理
void suppliermanagement(){
	while(1){
		system("cls");
		supplier s;
		menuSupplierManagement();
		int num=0;
		cin >> num;
		switch (num) {
		case 1:
			//添加供应商
			s.addSupplier();
			break;
		case 2:
			//删除供应商
			s.deleteSupplier();
			break;
		case 3:
			//修改供应商
			s.modifySupplier();
			break;
		case 4:
			//查询供应商
			s.querySupplier();
			break;
		case 5:
			return;
			break;
		}
	}
}
//客户管理
void customermanagement(){
	while(1){
		system("cls");
		customer c;
		int num = 0;
		menuCustomerManagement();
		cin >> num;
		switch (num) {
		case 1:
			//添加供应商
			c.addCustomer();
			break;
		case 2:
			//删除供应商
			c.deleteCustomer();
			break;
		case 3:
			//修改供应商
			c.modifyCustomer();
			break;
		case 4:
			//查询供应商
			c.queryCustomer();
			break;
		case 5:
			return;
			break;
		}
	}
}
//总功能
void function() {
	int choice;
	int num;
	good d;
	while (1) //死循环
	{
		system("cls");//清空屏幕
		menuLogin();
		cin >> choice;
		switch (choice)
		{
		case 1:
			//查询功能
			query();
			break;
		case 2:
			//仓库管理
			warehousemanagement();
			break;
		case 3:
			//供应商管理
			suppliermanagement();
			break;
		case 4: 
			//客户管理
			customermanagement();
			break;
		case 5:
			//返回
			return;
			break;
		default:
			cout << "提示:输入有误，请重新输入!" << endl;
			system("pause");
		}
	}
}

//主函数
int main()
{
	//设置控制台窗口和字体的颜色
	system("color 71");
	char choice;
	user u;
	while (1)
	{
		system("cls");
		menuSub();
		cin >> choice;
		switch (choice)
		{
		case '1':
			//注册功能
			u.Register();
			break;
		case '2':
			//登录功能
			u.Enter();
			break;
		case '3':
			//退出
			return 0;
			break;
		default:
			cout << "提示:输入有误，请重新输入!" << endl;
			system("pause");
		}
	}
}
